using CfgTable;
using IQIGame.Onigao.Framework.Editors;
using Sirenix.OdinInspector.Editor;
using System;
using UnityEditor;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    public enum TriggerType
    {
        None = 0,
        LeaveDeactive = 1,
        ShowByParam = 2
    }
    public enum StateParamType
    {
        None = 0,
        Speed = 1,
    }
    [Serializable]
    public class EntityEffectStateBind
    {
        public string stateName;
        public TriggerType triggerType;
        public ComparisonType animatorParamComparisonType;
        public StateParamType animatorParamType;
        public float animatorParamValue;
        public bool showOnMeetCondition;

        public class EntityEffectStateBindDrawer : OdinValueDrawer<EntityEffectStateBind>
        {
            protected override void DrawPropertyLayout(GUIContent label)
            {
                // 获取属性的引用
                var entry = this.ValueEntry;
                var property = this.Property;
                var variable = entry.SmartValue;

                EditorGUILayout.BeginVertical();

                EditorGUILayout.LabelField(property.Index.ToString(), EditorBindingUtil.IndexTextStyle, GUILayout.Width(30));
                variable.stateName = EditorGUILayout.TextField("状态名:", variable.stateName);
                variable.triggerType = (TriggerType)EditorGUILayout.EnumPopup("控制类型:", variable.triggerType);
                if (variable.triggerType == TriggerType.ShowByParam)
                {
                    variable.animatorParamComparisonType = (ComparisonType)EditorGUILayout.EnumPopup("[Param]比较类型:", variable.animatorParamComparisonType);
                    variable.animatorParamType = (StateParamType)EditorGUILayout.EnumPopup("[Param]参数类型:", variable.animatorParamType);
                    variable.animatorParamValue = EditorGUILayout.FloatField("[Param]参数值:", variable.animatorParamValue);
                    variable.showOnMeetCondition = EditorGUILayout.Toggle("[Param]显示(√)/隐藏(×):", variable.showOnMeetCondition);
                }

                EditorGUILayout.EndVertical();

                // 更新属性的值
                this.ValueEntry.SmartValue = variable;
            }
        }
    }
}
